/**
 * Created by zhangwenlei on 2017/5/24.
 */
BCP.bill.property.AttrBindingPropertyEditorControl = function(propDescriptor) {
    BCP.bill.property.AttrBindingPropertyEditorControl.superclass.constructor.call(this, propDescriptor);
};
BCP.bill.property.AttrBindingPropertyEditorControl.LABEL = "attrBindingEditor";
BCP.bill.property.AttrBindingPropertyEditorControl.getID = function(){
    return BCP.bill.property.AttrBindingPropertyEditorControl.LABEL;
};
COM.util.defineClass(BCP.bill.property.AttrBindingPropertyEditorControl, ADF.PropertyEditorControl, {
    createControl: function(propDescriptor) {
        var controlString =  '<div class="form-horizontal" style="margin-bottom:5px;"><div class="form-group" style="position: relative;">' +
            '<div class="col-sm-3" style="margin-left: 2px"><label style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap" for="'+propDescriptor.getName()+ '" class="control-label" title="'+propDescriptor.getHint()+'">'+propDescriptor.getTitle()+'</label></div>' +
            '<div class="col-sm-9 dropdown attrbinding" style="margin-left: -25px">' +
                '<div class="input-group">\
                    <input type="text" class="form-control" readonly value="' + propDescriptor.getValue() + '">\
                    <span class="input-group-btn">\
                        <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">\
                            <i class="iconfont icon-Group" style="font-size: 14px"></i>\
                        </button>\
                        <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">\
                        </ul>\
                    </span>\
                </div>\
            </div></div></div>';
        var control = COM.util.HTMLUtil.createELement(controlString);
        this.control = control[0];
        var $menu = COM.util.HTMLUtil.getChildren(this.control, ".dropdown-menu");
        $menu.append('<li></li>');
        var kclass = window.BCP.bill._bindings_.kclass;
        if(kclass){
            var arr = kclass.getAttArr().concat(kclass.getParentAttArr());
            for (var i = 0; i < arr.length; i++) {
                var element = arr[i];
                if(element.type.indexOf("[]") < 0){
                    $menu.append('<li>' + element.name + '</li>');
                }
            }
        }
    },
    getControl: function() {
        return this.control;
    },
    setValue: function(value) {
        COM.util.HTMLUtil.getChildren(this.control, "input").val(value);
    },
    getValue: function() {
        return COM.util.HTMLUtil.getChildren(this.control, "input").val();
    },
    bindChangeHandler: function(handler) {
        COM.util.HTMLUtil.getChildren(this.control, ".dropdown-menu").bind("click", function(e){
            var request = new AGEF.ChangeValueRequest();
            request.setPropertyName(this.propDescriptor.getName());
            request.setValue($(e.target).text());
            handler(request);
        }.bind(this));
    },
    getID : function(){
        return BCP.bill.property.AttrBindingPropertyEditorControl.LABEL;
    }
});